package hlhj.fhp.supreme.customview

import android.content.Context
import android.support.v7.widget.LinearLayoutManager
import android.view.LayoutInflater
import android.widget.LinearLayout
import android.widget.PopupWindow
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import hlhj.fhp.supreme.R
import kotlinx.android.synthetic.main.class_pop.view.*
import java.util.ArrayList

/**
 * Created by Administrator on 2018\5\9 0009.
 */
class RegisTypePop(private val context:Context,private val datas:ArrayList<String>,private val listener:OnRegisTypeClickListener) :PopupWindow(){
    private lateinit var adp:BaseQuickAdapter<String,BaseViewHolder>
    init {
        initPop()
    }

    fun initPop(){
        this.animationStyle= R.style.class_pop_style
        this.width= LinearLayout.LayoutParams.WRAP_CONTENT
        this.height= LinearLayout.LayoutParams.WRAP_CONTENT
        contentView= LayoutInflater.from(context).inflate(R.layout.class_pop,null)

        setRecyclerView()
    }

    private fun setRecyclerView() {
        adp=object :BaseQuickAdapter<String,BaseViewHolder>(R.layout.his_pop_item,datas){
            override fun convert(helper: BaseViewHolder?, item: String?) {
                helper?.setText(R.id.tv,item)
            }
        }

        contentView.listView.adapter=adp
        contentView.listView.layoutManager=LinearLayoutManager(context,LinearLayout.VERTICAL,false)

        adp.setOnItemClickListener { adapter, view, position ->
            listener.onClick(datas[position])
            dismiss()

        }
    }

    interface OnRegisTypeClickListener{
        fun onClick(name:String)
    }
}